<template>
    <el-input :value="code" @change="update" type="textarea" :rows="8"/>
</template>

<script>
    export default {
        props: {
            value: [Object, Function],
        },
        data() {
            return {
                code: '',
            }
        },
        methods: {
            update(val) {
                'use strict'
                try {
                    eval('val=' + val)
                    this.$emit('input', val)
                } catch (e) {
                }
            },
        },
        watch: {
            value: {
                immediate: true,
                handler(val) {
                    this.code = typeof val === 'function' ? val.toString() : JSON.stringify(val, null, 4)
                },
            },
        },
    }
</script>

<style lang="scss" scoped>

</style>
